package com.laoniu.controller.base;

import com.laoniu.annotation.OperateLog;
import com.laoniu.biz.base.BaseCustomBiz;
import com.laoniu.dto.RestResult;
import com.laoniu.dto.request.BaseCustomerRequestDto;
import com.laoniu.dto.response.BaseSupplierDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 客户信息表 前端控制器
 * </p>
 *
 * @author lxl
 * @since 2023-12-17
 */
@RestController
@RequestMapping("/base/customer")
public class BaseCustomerController {

    @Autowired
    private BaseCustomBiz customBiz;

    /**
     * 分页查询
     * @param requestDto
     * @return
     */
    @PostMapping("list")
    public RestResult list(@RequestBody BaseCustomerRequestDto requestDto){
        return RestResult.success(customBiz.pageList(requestDto));
    }

    /**
     * 新增客户
     * @param dto
     * @return
     */
    @PostMapping("add")
    @OperateLog(bizName = "客户信息", operateType = "新增客户", operateDesc = "管理后台添加客户")
    public RestResult add(@RequestBody BaseSupplierDto dto){
        customBiz.addCustomer(dto);
        return RestResult.success();
    }
    /**
     * 修改客户
     * @param dto
     * @return
     */
    @PostMapping("update")
    @OperateLog(bizName = "客户信息", operateType = "修改客户", operateDesc = "管理后台修改客户")
    public RestResult update(@RequestBody BaseSupplierDto dto){
        customBiz.updateCustomer(dto);
        return RestResult.success();
    }

    /**
     * 删除客户
     * @param dto
     * @return
     */
    @PostMapping("delete")
    @OperateLog(bizName = "客户信息", operateType = "删除客户", operateDesc = "管理后台删除客户")
    public RestResult delete(@RequestBody BaseSupplierDto dto){
        return customBiz.delete(dto.getId());
    }

    @PostMapping("listAll")
    public RestResult listAll(){
        return RestResult.success(customBiz.listAll());
    }
}
